﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UT3Bots.UTItems
{
	public class UTIdentifier : IComparable<UTIdentifier>, IEqualityComparer<UTIdentifier>, IEquatable<UTIdentifier>, IComparable
	{
		private string _id;

		internal UTIdentifier()
		{
		}

		internal UTIdentifier(string Id)
		{
			this._id = Id;
		}

		public override string ToString()
		{
			return this._id;
		}

		public override bool Equals(object obj)
		{
			if (obj is UTIdentifier)
			{
				return this._id == ((UTIdentifier)obj)._id;
			}
			return false;
		}

		public override int GetHashCode()
		{
			return this._id.GetHashCode();
		}

		public static bool operator ==(UTIdentifier a, UTIdentifier b)
		{
			if (System.Object.ReferenceEquals(a, b))
			{
				return true;
			}

			// If one is null, but not both, return false.
			if (((object)a == null) || ((object)b == null))
			{
				return false;
			}

			// Return true if the fields match:
			return a._id == b._id;
		}

		public static bool operator !=(UTIdentifier a, UTIdentifier b)
		{
			return !(a == b);
		}


		#region IComparable<UTIdentifier> Members

		public int CompareTo(UTIdentifier other)
		{
			return this._id.CompareTo(other._id);
		}

		#endregion

		#region IEqualityComparer<UTIdentifier> Members

		public bool Equals(UTIdentifier x, UTIdentifier y)
		{
			return x._id == y._id;
		}

		public int GetHashCode(UTIdentifier obj)
		{
			return obj._id.GetHashCode();
		}

		#endregion

		#region IEquatable<UTIdentifier> Members

		public bool Equals(UTIdentifier other)
		{
			return this._id == other._id;
		}

		#endregion

		#region IComparable Members

		public int CompareTo(object obj)
		{
			if (obj is UTIdentifier)
			{
				return this._id.CompareTo(((UTIdentifier)obj)._id);
			}
			return -1;
		}

		#endregion
	}
}
